﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITAP.ShprossesBuilder.Modelling.Measurement
{
    public class DimensionPriorityComparer : IComparer<Dimension>
    {
        private List<Type> dimensionPriority;

        public DimensionPriorityComparer(Type[] dimensionPriority)
        {
            this.dimensionPriority = new List<Type>(dimensionPriority);
        }

        #region IComparer<Dimension> Members

        public int Compare(Dimension x, Dimension y)
        {
            Type xType = x.GetType();
            Type yType = y.GetType();
            if (dimensionPriority.Contains(xType) && dimensionPriority.Contains(yType))
            {
                if (dimensionPriority.IndexOf(xType) < dimensionPriority.IndexOf(yType))
                    return -1;
                else if (dimensionPriority.IndexOf(xType) == dimensionPriority.IndexOf(yType))
                    return 0;
                else
                    return 1;
            }
            else
                throw new Exception();
        }

        #endregion
    }
}
